/**
 * TableColTrigger
 */
layui.define(['TableColTemplet', 'jquery', 'yunj'], function (exports) {

    let TableColTemplet = layui.TableColTemplet;
    let win = window;
    let doc = document;
    let $ = layui.jquery;

    class TableColTrigger extends TableColTemplet {

        constructor(options) {
            super(options);
            this.eventCode = '';            // 触发事件标识
            this.eventCodeIsStr = false;    // 触发事件标识是否为字符串
            this.eventType = '';            // 触发事件类型
            this.eventTitle = '';           // 触发事件标题
            this.eventUrl = '';             // 触发事件地址
        }

        async renderBefore() {
            let that = this;
            that.eventCode = that.args.event_code;
            that.eventCodeIsStr = yunj.isString(that.eventCode);
            that.eventType = that.args.event_type;
            that.eventTitle = that.args.event_title;
            that.eventUrl = that.args.event_url;
            return 'done';
        }

        layout() {
            let that = this;
            return `{{# 
                        let key = '${that.key}';
                        let value = d.${that.key};
                        let eventCode = ${that.eventCodeIsStr?`'${that.eventCode}';`:`${that.eventCode};`}
                        let eventType = '${that.eventType}';
                        let eventTitle = '${that.eventTitle}';
                        let eventUrl = '${that.eventUrl}';
                        if (eventUrl.indexOf('d.')!==-1) {
                            eventUrl = eval(eventUrl);
                        }
                        let eventConfig = {
                            'code':eventCode,
                            'type':eventType,
                            'title':eventTitle,
                            'class':'',
                            'url':eventUrl,
                            'confirm_form_fields':null,
                            'dropdown':false,
                            'show':'yes'
                        };
                        let buildTable = window.yunj.table['${that.tableId}'].getCurrBuildTable();
                        let layEvent = buildTable.generateLayEvent(buildTable.layEventLocation.column,eventConfig.code,eventConfig);
                     }}
                     <div class="table-row-trigger"><a style="color:var(--primary-color)" href="javascript:void(0)" lay-event="{{ layEvent }}">{{ value }}</a></div>`;
        }

    }

    exports('TableColTrigger', TableColTrigger);
});